package cn.hrlly.tao2shou.presenter;

import android.content.Context;

import cn.hrlly.tao2shou.biz.RequireListBiz;
import cn.hrlly.tao2shou.biz.RequireListBizImpl;
import cn.hrlly.tao2shou.domain.RequireList;
import cn.hrlly.tao2shou.listener.OnRequireListListener;
import cn.hrlly.tao2shou.view.view_interface.RequireListView;

/**
 * User: gengliang
 * Date: 2016-01-29
 * Time: 20:59
 */

public class RequireListPresenterImpl implements RequireListPresenter,OnRequireListListener {

    private RequireListBiz requireListBiz;
    private RequireListView requireListView;

    public RequireListPresenterImpl(RequireListView requireListView,Context context){
        this.requireListBiz=new RequireListBizImpl(this,context);
        this.requireListView=requireListView;
    }

    @Override
    public void showRequireList() {
        RequireList requireList=new RequireList();
        requireList.setPage(requireListView.getPage());
        requireList.setPageCount(requireListView.getPageCount());
        requireList.setClassification(requireListView.getClassification());
        requireListBiz.showRequireList(requireList);
    }

    @Override
    public void showCacheRequireList() {
        RequireList requireList=requireListBiz.getCacheRequireList();
        if(requireList!=null)
            requireListView.showListView(requireList);
    }

    @Override
    public void showRequireListSucc(RequireList requireList) {
        requireListView.showListView(requireList);

        //将获取到的信息缓存
        requireListBiz.saveCacheRequireList(requireList);
    }

    @Override
    public void showRequireListFail(String errorMessage) {
        requireListView.showMessage(errorMessage);
    }

    @Override
    public void showRequireListFail(int errorMessage) {
        requireListView.showMessage(errorMessage);
    }
}
